package logic

import (
	"context"
	"fmt"
	"good_srv/model/mysql"

	"good_srv/good"
	"good_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodInfoLogic {
	return &GoodInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodInfoLogic) GoodInfo(in *good.GoodInfoRequest) (*good.GoodInfoResponse, error) {
	// todo: add your logic here and delete this line
	var goods mysql.Good
	err := goods.FindGood(in.GoodId)
	if err != nil {
		return nil, fmt.Errorf("该商品不存在")
	}
	return &good.GoodInfoResponse{
		Title:  goods.Title,
		Cover:  goods.Cover,
		Status: goods.Status,
		Stock:  goods.Stock,
		Price:  float32(goods.Price),
		Likes:  goods.Likes,
		GoodId: int64(goods.ID),
	}, nil
}
